#pragma once
#include <iostream>

namespace ns_task
{
    class Task
    {
    public:
        int _sock;

    public:
        Task(int sock = -1) : _sock(sock){};
        int Run()
        {
            // while (true)
            // {
            char buffer[1024];
            memset(buffer, 0, sizeof(buffer));
            ssize_t s = read(_sock, buffer, sizeof(buffer) - 1);
            if (s > 0)
            {
                buffer[s] = 0;
                std::cout << "client #" << buffer << std::endl;
                std::string echo = ">>>server<<<";
                echo += buffer;
                write(_sock, echo.c_str(), echo.size());
            }
            else if (s == 0)
            {
                std::cout << "client quit..." << std::endl;
                // break;
            }
            else
            {
                std::cerr << " read error" << std::endl;
                // break;
            }
            close(_sock);
        }
        // }
        ~Task(){};
    };
}